package com.example.sixtrainingdemo.view;

import android.os.Bundle;
import android.widget.ListView;

import androidx.appcompat.app.AppCompatActivity;

import com.example.sixtrainingdemo.R;
import com.example.sixtrainingdemo.adapter.UserAdapter;
import com.example.sixtrainingdemo.database.DBHelper;
import com.example.sixtrainingdemo.entity.User;

import java.util.List;

public class UserListActivity extends AppCompatActivity {

    private ListView listView;
    private UserAdapter adapter;
    private DBHelper dbHelper;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_user_list); // 使用你提供的布局文件

        listView = findViewById(R.id.lv_user); // 绑定ListView

        dbHelper = DBHelper.getInstance(this); // 获取数据库帮助类实例

        // 调用selectAllUser()方法获取用户列表
        List<User> users = dbHelper.selectAllUser();
        adapter = new UserAdapter(users, this); // 创建适配器实例
        listView.setAdapter(adapter); // 设置适配器到ListView
    }
}